/* eslint-disable simple-import-sort/imports */
import TDesign from 'tdesign-vue-next';
import { createApp } from 'vue';

import App from './App.vue';
import router from './router';
import { store } from './store';
import i18n from './locales';
import directive from './directive';
import { setupFormCreate } from '@/utils/formCreate';
import 'tdesign-vue-next/es/style/index.css';
import '@/style/index.less';
import './permission';

const app = createApp(App);

const setupAll = async () => {
  // 1. 先注册 UI 框架 (TDesign)
  app.use(TDesign);
  
  // 2. 注册状态管理
  app.use(store);
  
  // 3. 注册国际化
  app.use(i18n);
  
  // 4. 注册自定义指令
  app.use(directive);
  
  // 5. 初始化 form-create (必须在 TDesign 之后注册)
  setupFormCreate(app);
  
  // 6. 注册路由
  app.use(router);
  
  // 等待路由加载完成
  await router.isReady();
  
  // 挂载应用
  app.mount('#app');
};

// 启动应用
setupAll().catch((error) => {
  console.error('应用初始化失败:', error);
});